using NUnit.Framework;
using SmartPeople.Framework.SecuritySpace;
using SmartPeople.Framework.SecuritySpace.Tests;

namespace SmartPeople.Framework.SecuritySpace.Provider.Tests
{
    [TestFixture]
    public class SecurityApplicationTests
    {
        //SecApp_001
        [Test, Description("Create roles and users for application")]
        public void CreateApplicationUsers()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
            securitySpaceHRMS.Clear();

            securitySpaceHRMS.Roles.CreateRole(TestRoles.Operators);
            ISecurityUser user1 = securitySpaceHRMS.Users.CreateUser(TestUsers.User1, "user1g@acme.com");
            string[] roleNames = new string[] {TestRoles.Operators};
            string[] userNames = new string[] {user1.UserName};
            securitySpaceHRMS.Roles.AddUsersToRoles(userNames, roleNames);
            Assert.AreEqual(1, securitySpaceHRMS.Roles.Count);
            Assert.AreEqual(1, securitySpaceHRMS.Users.Count);

            securitySpaceHRMS.Clear();
        }


        //SecApp_002
        [Test, Description("Create the same role for two security applications")]
        public void CreateSameRolesForTwoSecurityApplications()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
            securitySpaceHRMS.Clear();

            ISecuritySpace securitySpaceCRM = TestsHelper.GetSecuritySpace("CRM");
            securitySpaceCRM.Clear();

            securitySpaceHRMS.Roles.CreateRole(TestRoles.Administrators);
            securitySpaceCRM.Roles.CreateRole(TestRoles.Administrators);
            Assert.AreEqual(1, securitySpaceHRMS.Roles.Count);
            Assert.AreEqual(1, securitySpaceCRM.Roles.Count);
            Assert.IsTrue(securitySpaceHRMS.Roles.RoleExists(TestRoles.Administrators));
            //assert true for crm application also
            Assert.IsTrue(securitySpaceCRM.Roles.RoleExists(TestRoles.Administrators));

            securitySpaceHRMS.Clear();
        }

        //SecApp_004
        [Test, Description("Create two roles for a single applications")]
        public void CreateTwoRolesForASingleSecurityApplication()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
            securitySpaceHRMS.Clear();

            securitySpaceHRMS.Roles.CreateRole(TestRoles.Administrators);
            securitySpaceHRMS.Roles.CreateRole(TestRoles.Operators);
            Assert.AreEqual(2, securitySpaceHRMS.Roles.Count);

            securitySpaceHRMS.Clear();
        }


        //SecApp_005
        [Test, Description("Delete two roles for a single application")]
        public void DeleteTwoRolesForASingleSecurityApplication()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
            securitySpaceHRMS.Clear();

            securitySpaceHRMS.Roles.CreateRole(TestRoles.Administrators);
            securitySpaceHRMS.Roles.CreateRole(TestRoles.Operators);
            Assert.AreEqual(2, securitySpaceHRMS.Roles.Count);
            Assert.IsTrue(securitySpaceHRMS.Roles.RoleExists(TestRoles.Administrators));
            Assert.IsTrue(securitySpaceHRMS.Roles.RoleExists(TestRoles.Operators));
            securitySpaceHRMS.Roles.DeleteRole(TestRoles.Administrators);
            securitySpaceHRMS.Roles.DeleteRole(TestRoles.Operators);
            Assert.AreEqual(0, securitySpaceHRMS.Roles.Count);

            securitySpaceHRMS.Clear();
        }

        //SecApp_006
        [Ignore("To be decided")]
        [Test, Description("Create a security application")]
        public void CreateASecurityApplication()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
        }

        //SecApp_007
        [Test]
        public void DeleteASecurityApplication()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
            securitySpaceHRMS.Clear();
        }

        //SecApp_008
        [Test]
        [Ignore("To be decided")]
        public void CreateADuplicateSecurityApplication()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace("HRMS");
            //securitySpaceHRMS.Clear();
            ISecuritySpace securitySpaceCRM = TestsHelper.GetSecuritySpace("HRMS");
            //securitySpaceCRM.Clear();
        }

        //SecApp_009
        [Test, Description("Create a security application")]
        public void CreateASecurityApplicationWithNullName()
        {
            ISecuritySpace securitySpaceHRMS = TestsHelper.GetSecuritySpace();
        }
    }
}